home *** CD-ROM | disk | FTP | other *** search
/ Megahits 5 / Megahits 5 (1994)(GTI - Rhein-Main-Soft)(DE)(Disc 2 of 2)[!].iso / archive / print / virtprinters2.lha / iff_printer_source / render.c < prev    next >
C/C++ Source or Header  |  1993-06-27  |  5KB  |  147 lines

  1. /****************************************************************************
  2.  *
  3.  *        IFF_Printer driver.
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/nodes.h>
  8. #include <exec/lists.h>
  9. #include <exec/memory.h>
  10. #include <devices/prtbase.h>
  11. #include <devices/printer.h>
  12. #include <iffp/packer.h>
  13.  
  14. #include <clib/exec_protos.h>
  15.  
  16. #include "task.h"
  17.  
  18. extern struct Library *AbsExecBase;
  19.  
  20. extern struct PrinterData *PD;
  21. extern struct PrinterExtendedData *PED;
  22. extern void SetDensity(ULONG);
  23. extern void Transfer(struct PrtInfo *PInfo, UWORD y, BYTE *ptr, UWORD colors[]);
  24. extern int SendMyMsg(int i);
  25.  
  26. #define MAXCOLORBUFS 3
  27.  
  28. void Eject(void);
  29.  
  30.     BYTE *PackBuf;
  31.         UWORD BufSize, ColorSize;
  32.         UBYTE *ptr;
  33.     UWORD colors[MAXCOLORBUFS];
  34.  
  35. int Render(long ct, long x, long y, long status)
  36. {
  37.         int i, err;
  38.  
  39.         err=PDERR_NOERR;
  40.         switch(status) {
  41.                 case 0 : /* Master Initialization */
  42.                         /*
  43.                                 ct      - pointer to IODRPReq structure.
  44.                                 x       - width of printed picture in pixels.
  45.                                 y       - height of printed picture in pixels.
  46.                         */
  47.                         BufSize = ((PED->ped_MaxXDots + 15) / 16) * 2;
  48.             ColorSize = BufSize;
  49.             if (PD->pd_Preferences.PrintShade == SHADE_COLOR)
  50.                 BufSize *= 3;
  51.             colors[0] = ColorSize * 0; /* Black or yellow */
  52.             colors[1] = ColorSize * 1; /* Magenta */
  53.             colors[2] = ColorSize * 2; /* Cyan */
  54.                         PD->pd_PrintBuf = AllocMem(BufSize, MEMF_ANY);
  55.                         if (PD->pd_PrintBuf == NULL) {
  56.                                 err = PDERR_BUFFERMEMORY; /* no mem */
  57.                         }
  58.                         else {
  59.                 PackBuf = AllocMem(MaxPackedSize(BufSize),
  60.                     MEMF_ANY);
  61.                 if (PackBuf == NULL) {
  62.                     err = PDERR_BUFFERMEMORY;
  63.                     FreeMem(PD->pd_PrintBuf, BufSize);
  64.                     PD->pd_PrintBuf = NULL;
  65.                 }
  66.                 else if (SendMyMsg(myCode_OpenFile)
  67.                     == NULL) err = PDERR_BUFFERMEMORY;
  68.             }
  69.                         break;
  70.  
  71.                 case 1 : /* Scale, Dither and Render */
  72.                         /*
  73.                                 ct      - pointer to PrtInfo structure.
  74.                                 x       - 0.
  75.                                 y       - row # (0 to Height - 1).
  76.                         */
  77.                         Transfer((struct PrtInfo *)ct, y, PD->pd_PrintBuf,
  78.                 colors);
  79.                         err = PDERR_NOERR; /* all ok */
  80.                         break;
  81.  
  82.                 case 2 : /* Dump Buffer to Printer */
  83.                         /*
  84.                                 ct      - 0.
  85.                                 x       - 0.
  86.                                 y       - # of rows sent (1 to NumRows).
  87.                         */
  88.             if (SendMyMsg(myCode_WriteLine) == NULL) {
  89.                 err = PDERR_CANCEL;
  90.             }
  91.                         break;
  92.  
  93.                 case 3 : /* Clear and Init Buffer */
  94.                         /*
  95.                                 ct      - 0.
  96.                                 x       - 0.
  97.                                 y       - 0.
  98.                         */
  99.                         ptr = PD->pd_PrintBuf;
  100.                         i = BufSize;
  101.                         do {
  102.                                 *ptr++ = 0;
  103.                         } while (--i);
  104.                         break;
  105.  
  106.                 case 4 : /* Close Down */
  107.                         /*
  108.                                 ct      - error code.
  109.                                 x       - io_Special flag from IODRPReq struct
  110.                                 y       - 0.
  111.                         */
  112.                         err = PDERR_NOERR; /* assume all ok */
  113.                         /* if user did not cancel the print */
  114.                         if (ct != PDERR_CANCEL) {
  115.                             /* if want to unload paper */
  116.                             if (!(x & SPECIAL_NOFORMFEED)) {
  117.                                 /* eject paper */
  118.                     Eject();
  119.                                 }
  120.                         }
  121.                         if (PD->pd_PrintBuf != NULL) {
  122.                                 FreeMem(PD->pd_PrintBuf, BufSize);
  123.                         }
  124.             if (PackBuf != NULL) {
  125.                 FreeMem(PackBuf, MaxPackedSize(BufSize));
  126.                 PackBuf = NULL;
  127.             }
  128.                         break;
  129.  
  130.                 case 5 : /* Pre-Master Initialization */
  131.                         /*
  132.                                 ct      - 0 or pointer to IODRPReq structure.
  133.                                 x       - io_Special flag from IODRPReq struct
  134.                                 y       - 0.
  135.                         */
  136.                         /* select density */
  137.                         SetDensity(x & SPECIAL_DENSITYMASK);
  138.                         break;
  139.         }
  140.         return(err);
  141. }
  142.  
  143. void Eject(void) {
  144.     SendMyMsg(myCode_CloseFile);
  145. }
  146.  
  147.